package cn.tedu.csmall.stock.webapi.quartz;

import cn.tedu.csmall.commons.pojo.stock.entity.Stock;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.math.RandomUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.time.LocalDateTime;

@Slf4j
public class QuartzJob implements Job {

//    @Autowired
//    private KafkaTemplate<String,String> kafkaTemplate;

    public static final String TOPIC_STOCK_KEY="myStock";

    static int i=1;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 当前Job是为了测试Quartz效果的测试类,输出当前时间作为简单操作
        log.info("---------------------"+ LocalDateTime.now() +"----------------------");
        Stock stock=new Stock();
        stock.setId(i++);
        stock.setCommodityCode("PC100");
        stock.setReduceCount(1+ RandomUtils.nextInt(10));

        Gson gson=new Gson();
        String json=gson.toJson(stock);

        log.info("即将发送消息:{}",json);
        //kafkaTemplate.send(TOPIC_STOCK_KEY,json);

    }
}
